<html>
<head><meta charset="utf-8"><title>lazy norm recursive impls · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20recursive.20impls.html">lazy norm recursive impls</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223825249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/lazy%20norm%20recursive%20impls/near/223825249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20recursive.20impls.html#223825249">(Jan 24 2021 at 17:37)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(const_generics, const_evaluatable_checked)]</span><span class="w"></span>
<span class="cp">#![allow(incomplete_features)]</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">Dummy</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="k">trait</span><span class="w"> </span><span class="n">Helper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">recurse</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">usize</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Helper</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Dummy</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">Dummy</span><span class="o">&lt;</span><span class="p">{</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">}</span><span class="o">&gt;</span>: <span class="nc">Helper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">recurse</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">N</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="o">&lt;</span><span class="n">Dummy</span><span class="o">&lt;</span><span class="p">{</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">}</span><span class="o">&gt;</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">Helper</span><span class="o">&gt;</span>::<span class="n">recurse</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Helper</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Dummy</span><span class="o">&lt;</span><span class="mi">0</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">recurse</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="mi">1</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">factorial</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="nc">where</span><span class="w"> </span><span class="n">Dummy</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span>: <span class="nc">Helper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="o">&lt;</span><span class="n">Dummy</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">Helper</span><span class="o">&gt;</span>::<span class="n">recurse</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="fm">assert_eq!</span><span class="p">(</span><span class="n">factorial</span>::<span class="o">&lt;</span><span class="mi">3</span><span class="o">&gt;</span><span class="p">(),</span><span class="w"> </span><span class="mi">6</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=bfade98af1530043fe78a310c57044c3">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=bfade98af1530043fe78a310c57044c3</a></p>



<a name="223825301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/lazy%20norm%20recursive%20impls/near/223825301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20recursive.20impls.html#223825301">(Jan 24 2021 at 17:38)</a>:</h4>
<p>with <a href="https://github.com/rust-lang/rust/issues/81339">#81339</a> this should have worked</p>



<a name="223825308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/lazy%20norm%20recursive%20impls/near/223825308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20recursive.20impls.html#223825308">(Jan 24 2021 at 17:38)</a>:</h4>
<p>if not for one fun interaction with lazy normalization</p>



<a name="223825327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/lazy%20norm%20recursive%20impls/near/223825327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20recursive.20impls.html#223825327">(Jan 24 2021 at 17:39)</a>:</h4>
<p>where we continue to treat <code>N - 1</code> as an opaque projection even if we already substituted <code>N</code> with a concrete value</p>



<a name="223825387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/lazy%20norm%20recursive%20impls/near/223825387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20recursive.20impls.html#223825387">(Jan 24 2021 at 17:40)</a>:</h4>
<p>so we never actually reject the generic impl here, even if we have something like <code>(((((((((((3 - 1) - 1) - 1) - 1) - 1) - 1) ...</code></p>



<a name="223825390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/lazy%20norm%20recursive%20impls/near/223825390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20recursive.20impls.html#223825390">(Jan 24 2021 at 17:40)</a>:</h4>
<p>causing an overflow error</p>



<a name="223825406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/lazy%20norm%20recursive%20impls/near/223825406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/lazy.20norm.20recursive.20impls.html#223825406">(Jan 24 2021 at 17:41)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error[E0275]: overflow evaluating the requirement `Dummy&lt;{ N - 1 }&gt;: Helper`
   |
   = help: consider adding a `#![recursion_limit=&quot;256&quot;]` attribute to your crate (`recursive_factorial`)
   = note: required because of the requirements on the impl of `Helper` for `Dummy&lt;{ N - 1 }&gt;`
   = note: 127 redundant requirements hidden
   = note: required because of the requirements on the impl of `Helper` for `Dummy&lt;{ N - 1 }&gt;`
</code></pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>